package com.net.oil.util.share;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.net.oil.R;

import java.util.ArrayList;

public class ShareAdapter extends BaseAdapter {
    private ArrayList<ShareMenuItem> list;
    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public ShareAdapter(Context context, ArrayList<ShareMenuItem> list) {
        this.list = list;
        this.mContext = context;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ShareAdapter.ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.share_grid_item, null);
            viewHolder = new ShareAdapter.ViewHolder();
            viewHolder.title = (TextView) convertView.findViewById(R.id.share_menu_item_text);
            viewHolder.image = (ImageView) convertView.findViewById(R.id.share_menu_item_img);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ShareAdapter.ViewHolder) convertView.getTag();
        }
        //viewHolder.image.setImageResource(ResContainer.getResourceId(mContext,"drawable",list.get(position).mIcon));
        viewHolder.image.setImageResource(list.get(position).getIcon());
        viewHolder.title.setText(list.get(position).getName());
        // 设置图标的宽和高
        return convertView;
    }

    class ViewHolder {
        public ImageView image;
        public TextView title;
    }
}
